<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <BreakSpace label='操作记录' />
    <FilterTable
      ref="table"
      :columns="columns1"
      :dataSource="tableLists"
      :isSelectColumn="false"
      height='auto'
      :onColumnsChange="columns => this.columns1 = columns"
    >

    </FilterTable>
    <div style="height:47px;"></div>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
    </div>
  </div>
</template>
<script>
import {getList,getDetail,updatePlateApply,vehicleConfiguration,getflowList} from '@/api/omSale/subsidy/subsidyAudit/index.js'
import { dictionary } from '@/utils/dictMixin';
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom(),
      issearch:false,
      fetchApi:()=>{},
      fetchParams:{},
      columns:this.createdTable(),
      columns1:this.createdTables(),
      isopen:true,
    }
  },
  components:{
  },
  watch:{
    'data':{
      handler(newName,oldName){
        this.getDetail(newName)
      },
      deep:true
    }
  },
  props:['data'],
  mixins:[dictionary],
  methods:{
    createdFrom(){
      return [
        {
          type: 'BREAK_SPACE',
          label: '行驶证信息',
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '公告号',
          fieldName: 'announceNo',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '客户类型',
          fieldName: 'customerType',
          placeholder: '请选择',
          disabled:true,
          itemList:this.createDictList('1523'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '客户姓名',
          fieldName: 'customerName',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请选择', trigger: 'blur' }],
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          },
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'plateNumber',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '行驶证号',
          fieldName: 'drivingNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '上牌省份',
          fieldName: 'plateProvince',
          placeholder: '请选择',
          itemList:[],
          disabled:true,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '上牌城市',
          fieldName: 'plateCity',
          placeholder: '请选择',
          itemList:[],
          disabled:true,
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'DATE',
          label: '行驶证注册日期',
          fieldName: 'drivingRegisteDate',
          placeholder: '请选择',
          disabled:true,
          dateType:'exactdate',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          placeholder: '请输入',
          disabled:true,
          selfCols:2,
        },

        {
          type: 'SELECT',
          label: '车辆性质',
          fieldName: 'vehicleType',
          placeholder: '请选择',
          disabled:true,
          itemList: this.createDictList('4103')
        },


        {
          type: 'BREAK_SPACE',
          label: '发票信息',
        },
        {
          type: 'DATE',
          label: '开票日期',
          fieldName: 'invoiceDate',
          placeholder: '请选择',
          disabled:true,
          dateType:'exactdate',
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '发票号码',
          fieldName: 'invoiceNo',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '证件类型',
          fieldName: 'cardType',
          disabled:true,
          placeholder: '请选择',
          itemList:this.createDictList('1508'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '证件号码',
          fieldName: 'cardNo',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '开票价格',
          fieldName: 'invoiceAmount',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '发票代码',
          fieldName: 'invoiceCode',
          placeholder: '请输入',
          disabled:true,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'CHECKBOX',
          label: '车价是否含国补',
          fieldName: 'includeLocalSubsidy',
          disabled:true,
          placeholder: '请选择',
          itemList:this.createDictList('1004'),

        },
        {
          type: 'INPUT',
          label: '国补金额',
          fieldName: 'localSubsidyAmount',
          placeholder: '请输入',
          disabled:true,
          offsetRightCols:1,
          rules: [{ required: false}],
        },
        {
          type: 'CHECKBOX',
          label: '车价是否含地补',
          fieldName: 'includeNationalSubsidy',
          disabled:true,
          placeholder: '请选择',
          itemList:this.createDictList('1004'),

        },
        {
          type: 'INPUT',
          label: '地补金额',
          fieldName: 'nationalSubsidyAmount',
          placeholder: '请输入',
          disabled:true,
          offsetRightCols:1,
          rules: [{ required: false}],
        },
        {
          type: 'BREAK_SPACE',
          label: '客户信息',
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'linkMan',
          disabled:true,
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'linkPhone',
          disabled:true,
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'provinceId',
          disabled:true,
          placeholder: '请选择',
          itemList:[],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '城市',
          fieldName: 'cityId',
          disabled:true,
          placeholder: '请选择',
          itemList:[],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'SELECT',
          label: '县区',
          fieldName: 'districtId',
          disabled:true,
          placeholder: '请选择',
          itemList:[],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'zipCode',
          disabled:true,
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'TEXT_AREA',
          label: '详细地址',
          fieldName: 'linkAddress',
          placeholder: '请输入',
          disabled:true,
          selfCols:2,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '审批驳回次数',
          fieldName: 'rejectTimes',
          disabled:true,
          placeholder: '请输入',
        },
        {
          type: 'CHECKBOX',
          label: '是否二网销售',
          fieldName: 'isSecondSales',
          disabled:true,
          placeholder: '请选择',
          itemList:this.createDictList('1004'),
        },
        {
          type: 'BREAK_SPACE',
          label: '审批信息',
        },
        {
          type: 'TEXT_AREA',
          label: '审批意见',
          fieldName: 'checkDesc',
          placeholder: '请输入',
          selfCols:3,
          disabled:true,
          rules: [{ required: false}],
        },
      ]
    },
    createdTable(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '单据执行前状态',
          dataIndex: 'djzxqzt',
          sorter: true,
          filter: true,
          filterType: 'input',

        },
        {
          title: '单独执行后状态',
          dataIndex: 'ddzxhzt',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作人员',
          dataIndex: 'czry',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作时间',
          dataIndex: 'czsj',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作类型',
          dataIndex: 'czlx',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '审批意见',
          dataIndex: 'spyj',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ]
    },
    getDetail(data){
      console.log(data,'data')
      for (let i in data) {
      this.formList.map(x => {
          if(x.fieldName=='isSecondSales'){
            x.initialValue=data.isSecondSales?`${data.isSecondSales}`:''
          }else if (i == x.fieldName) {
            x.initialValue = data[i];
          }
          if(x.fieldName=='fpfj'){
            let arr=[]
            data.enclosures.map(x=>{
              if(x.enclosureType=='invoiceAddress'){
                arr.push({name:x.enclosureName,url:x.enclosureUrl})
              }
            })
            x.initialValue=arr;
          }
          if(x.fieldName=='xszfj'){
            let arr=[]
            data.enclosures.map(x=>{
              if(x.enclosureType=='drivingAddress'){
                arr.push({name:x.enclosureName,url:x.enclosureUrl})
              }
            })
            x.initialValue=arr;
          }
          if(x.fieldName=='qtfj'){
            let arr=[]
            data.enclosures.map(x=>{
              if(x.enclosureType=='otherAddress'){
                arr.push({name:x.enclosureName,url:x.enclosureUrl})
              }
            })
            x.initialValue=arr;
          }
        });
      }
      if(data.includeLocalSubsidy==1){
        this.formList.find(x=>x.fieldName=='localSubsidyAmount').rules=[{ required: true, message: '请输入', trigger: 'blur' }]
      }else{
        this.formList.find(x=>x.fieldName=='localSubsidyAmount').rules=[{ required: false}]
      }
      if(data.includeNationalSubsidy==1){
        this.formList.find(x=>x.fieldName=='nationalSubsidyAmount').rules=[{ required: true, message: '请输入', trigger: 'blur' }]
      }else{
        this.formList.find(x=>x.fieldName=='nationalSubsidyAmount').rules=[{ required: false}]
      }
      this.getflowList(data)
      this.formList.find(x=>x.fieldName=='plateProvince').itemList=this.createRegionsList()
      this.formList.find(x=>x.fieldName=='plateCity').itemList=this.createcityList(data.plateProvince)
      this.formList.find(x=>x.fieldName=='provinceId').itemList=this.createRegionsList()
      this.formList.find(x=>x.fieldName=='cityId').itemList=this.createcityList(data.provinceId)
      this.formList.find(x=>x.fieldName=='districtId').itemList=this.district(data.cityId)
      if(data.applyStatus==60191004){
        this.formList.find(x=>x.fieldName=='checkDesc').rules=[{ required: true, message: '请输入', trigger: 'blur' }]
      }else{
        this.formList.find(x=>x.fieldName=='checkDesc').rules=[{ required: false}]
      }

      console.log(data);
    },
    seacherFun(){
    },
    changeHandle(val){

    },
    async getUser(){
      let res=await getDealerUser()
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId }));
      this.columns1.find(item => item.dataIndex === 'updated_by').editItems = empList; //操作姓名
      this.columns1.find(item => item.dataIndex === 'updated_by').filterItems = empList;
    },
    async getflowList(data){
      let res=await getflowList({id:data.id})
      if(res.data&&res.data.length>0){
        this.tableLists=res.data||[]
      }

    },
    createdTables(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作后状态',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6019'),
          render: (p) => {
            return <span >{this.createDictText(p.row.status, '6019')}</span>;
          },

        },
        {
          title: '操作人员',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作时间',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
        },
        {
          title: '审核意见',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ]
    },
  }
}
</script>
